package com.tesis_2.UI;

import java.util.ArrayList;

import org.json.JSONException;

import com.example.t2_clientback.R;
import com.example.t2_clientback.R.menu;
import com.tesis_2.BL.BLLocales;
import com.tesis_2.MO.MOLocal;
import com.tesis_2.Utils.UTLocalesAdapter;
import com.tesis_2.Utils.UTLocalesSimpleAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;

public class UILocales extends ListActivity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_uilocales);
		
		ArrayList<MOLocal> lsLocales = new ArrayList<MOLocal>();
		
		try {
			BLLocales.fillLocales();
			lsLocales = BLLocales.getLsLocal();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			setListAdapter( new UTLocalesAdapter(this, lsLocales));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_uilocales, menu);
		return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
	    
		Intent intent; 
		
		switch (item.getItemId()) 
	    {
	        case R.id.optAgregar_local:
	        	intent = new Intent(this, UISeleccionarRestLocal.class);
				intent.putExtra("modo", 1);
				startActivity(intent);
	        break;
	        
	        default: 
	        	
	        break;
	    }
	    return false;
	} 

}
